import type { Request, ResponseToolkit } from "@hapi/hapi";
import Hapi from "@hapi/hapi";
import { User, Notes } from "../../model/index";

let route: Hapi.ServerRoute<Hapi.ReqRefDefaults> = {
  path: "/delUser",
  method: "get",
  handler: async (r: any, h: ResponseToolkit) => {
    try {
      const user: any = await User.findOne({ _id: r.query.id });
      await User.deleteOne({ _id: user._id });
      await Notes.deleteMany({ pid: user._id });
      console.log(user, "user");
      return { code: 200, data: user, message: "删除成功" };
    } catch (error) {
      return error;
    }
  },
  options: {
    tags: ["api"],
  },
};
export default route;
